home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.04 Apr 90 / Messenger Files / dDriver Folder / Preferences.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-04  |  11.5 KB  |  465 lines  |  [TEXT/KAHL]

  1. /* *******************************
  2.  
  3. File: Preferences.c
  4. Function: Handle all operations for this Modal Dialog
  5. History: 9/21/89 Original by Prototyper.  
  6. Modified: 10/3/89 by Kirk Chase.  Clean up routines
  7.  
  8. ******************************* */
  9.  
  10. #include "Preferences.h"
  11.  
  12. static pascal char  MyFilter (DialogPtr   theDialog,  EventRecord   *theEvent,  short  *itemHit);
  13.  
  14. static void  Refresh_Dialog(DialogPtr    GetSelection);
  15.  
  16.  
  17.     /* *********************************** */
  18.     /* These are the other includes for general routines */
  19.  
  20. #include "string.h"
  21. #include "pascal.h"
  22. #include "Messenger.h"
  23.  
  24.     /* *********************************** */
  25. #define      NIL    0
  26.  
  27. #define  I_OK   1
  28. #define  I_Cancel   2
  29. #define  I_B1Text   8
  30. #define  I_B2Text   9
  31. #define  I_B3Text   10
  32. #define  I_CQText   11
  33. #define  I_Default   16
  34. #define  I_Icons   17
  35. #define  I_Buttons   18
  36. #define  I_Position   19
  37. static char   ExitDialog; 
  38. static Point   myPt; 
  39. static char   ChangedSelection; 
  40. static MenuHandle   tempMenu; 
  41. static long    Result;
  42. static short   Popup_I_Default;
  43. static short   Popup_I_Icons;
  44. static short   Popup_I_Buttons;
  45. static short   Popup_I_Position;
  46. static Rect PopUpDefaultRect, PopUpIconRect, PopUpButtonsRect, PopUpCenterRect;
  47.  
  48. /* ********************************************* */
  49.  
  50. /* RefreshDialog()
  51.     Draw non-dialog items */ 
  52. static void  Refresh_Dialog(GetSelection) 
  53. DialogPtr    GetSelection;
  54. Rect    tempRect;
  55. short    DType;
  56. Handle    DItem;
  57.  
  58. /* Do Default Button */
  59. GetDItem(GetSelection,I_OK, &DType, &DItem, &tempRect);
  60. PenSize(3, 3);
  61. InsetRect(&tempRect, -4, -4);
  62. FrameRoundRect(&tempRect, 16, 16); 
  63. PenSize(1, 1); 
  64.  
  65. /* Draw the dividing lines */
  66. MoveTo(30,60);
  67. LineTo(371,60);
  68. MoveTo(28,24);
  69. LineTo(370,24);
  70. MoveTo(33,148);
  71. LineTo(370,148);
  72. MoveTo(245,155);
  73. LineTo(245,234);
  74.  
  75. /* Draw PopUps */
  76. TextFont(systemFont);
  77. TextSize(12);
  78.  
  79. /* Draw Default PopUp */
  80. MoveTo(220,49);
  81. DrawString("\pDefault:");
  82. SetRect(&tempRect,274,36,301,53);
  83. EraseRect(&tempRect);
  84. MoveTo(287,49);
  85. switch (Popup_I_Default) {
  86.     case 1: 
  87.         DrawString("\p1");
  88.         break;
  89.     case 2: 
  90.         DrawString("\p2");
  91.         break;
  92.     case 3: 
  93.         DrawString("\p3");
  94.         break;
  95.     default:
  96.         DrawString("\p????");
  97.         break;
  98.     }
  99.  
  100. FrameRect(&tempRect);
  101. MoveTo(tempRect.left + 1, tempRect.bottom);
  102. LineTo(tempRect.right, tempRect.bottom);
  103. LineTo(tempRect.right, tempRect.top + 1);
  104.  
  105. /* Draw PopUp Icons */
  106. MoveTo(30,209);
  107. DrawString("\pIcons:");
  108. SetRect(&tempRect,72,196,141,213);
  109. EraseRect(&tempRect);
  110. MoveTo(85,209);
  111. switch (Popup_I_Icons) {
  112.     case 1: 
  113.         DrawString("\pNone");
  114.         break;
  115.     case 2: 
  116.         DrawString("\pStop");
  117.         break;
  118.     case 3: 
  119.         DrawString("\pNote");
  120.         break;
  121.     case 4: 
  122.         DrawString("\pCaution");
  123.         break;
  124.     default:
  125.         DrawString("\p????");
  126.         break;
  127.     }
  128. FrameRect(&tempRect);
  129. MoveTo(tempRect.left + 1, tempRect.bottom);
  130. LineTo(tempRect.right, tempRect.bottom);
  131. LineTo(tempRect.right, tempRect.top + 1);
  132.  
  133. /* Draw PopUp Buttons */
  134. MoveTo(85,49);
  135. DrawString("\pButtons:");
  136. SetRect(&tempRect,142,36,169,53);
  137. EraseRect(&tempRect);
  138. MoveTo(155,49);
  139. switch (Popup_I_Buttons) {
  140.     case 1: 
  141.         DrawString("\p0");
  142.         break;
  143.     case 2: 
  144.         DrawString("\p1");
  145.         break;
  146.     case 3: 
  147.         DrawString("\p2");
  148.         break;
  149.     case 4: 
  150.         DrawString("\p3");
  151.         break;
  152.     default:
  153.         DrawString("\p????");
  154.         break;
  155.     }
  156. FrameRect(&tempRect);
  157. MoveTo(tempRect.left + 1, tempRect.bottom);
  158. LineTo(tempRect.right, tempRect.bottom);
  159. LineTo(tempRect.right, tempRect.top + 1);
  160.  
  161. /* Draw Position PopUp */
  162. MoveTo(30,174);
  163. DrawString("\pPosition:");
  164. SetRect(&tempRect,89,161,168,178);
  165. EraseRect(&tempRect);
  166. MoveTo(102,174);
  167. switch (Popup_I_Position)
  168. {
  169.     case 1: 
  170.         DrawString("\pCentered");
  171.         break;
  172.     case 2: 
  173.         DrawString("\pTop Third");
  174.         break;
  175.     default:
  176.         DrawString("\p????");
  177.         break;
  178. }
  179. FrameRect(&tempRect);
  180. MoveTo(tempRect.left + 1, tempRect.bottom);
  181. LineTo(tempRect.right, tempRect.bottom);
  182. LineTo(tempRect.right, tempRect.top + 1);
  183. } /* end of Refresh_Dialog */
  184.  
  185. /* ********************************************* */
  186.  
  187. /* MyFilter()
  188.     Filter proc for modal dialog; just checks for updates and PopUp menus */
  189. static pascal char  MyFilter (theDialog, theEvent, itemHit)
  190. DialogPtr    theDialog;
  191. EventRecord    *theEvent;
  192. short    *itemHit;
  193. {
  194. char   theExit;
  195.  
  196. theExit = FALSE;
  197. if (theEvent->what == updateEvt) Refresh_Dialog(theDialog);
  198. if (theEvent->what == mouseDown) { /* Mouse Down, check if in PopUps */
  199.     myPt = theEvent->where;
  200.     GlobalToLocal(&myPt);
  201.      
  202.     if (PtInRect(myPt,&PopUpDefaultRect) || PtInRect(myPt,&PopUpIconRect)
  203.         || PtInRect(myPt,&PopUpButtonsRect) || PtInRect(myPt,&PopUpCenterRect)) {                               
  204.         *itemHit = 999; /* PopUp Menu Flag */
  205.         theExit = TRUE;
  206.         } /* in a PopUp */
  207.     }
  208.  
  209.     return(theExit);
  210. } /* End of MyFilter */
  211.  
  212. /* ********************************************* */ 
  213.  
  214. /* D_Preferences()
  215.     Preference dialog to handle text dialog options */
  216. void   D_Preferences()
  217. {
  218. DialogPtr    GetSelection;
  219. Rect    tempRect;
  220. short    DType;
  221. Handle    DItem;
  222. short    itemHit;
  223.     
  224. GetSelection = GetNewDialog(2, NIL, (WindowPtr)-1);
  225.  
  226. SetRect(&PopUpCenterRect, 25,160,175,180);
  227. SetRect(&PopUpButtonsRect, 80,35,176,55);                            
  228. SetRect(&PopUpDefaultRect, 215,35,308,55);
  229. SetRect(&PopUpIconRect, 25,195,148,215);
  230.  
  231. /* Setup initial conditions */
  232. Popup_I_Default = MInfo.defaultItem;
  233. Popup_I_Icons = MInfo.dIcon + 2;
  234. Popup_I_Buttons = MInfo.Buttons + 1;
  235. Popup_I_Position = MInfo.dPlace - 1;
  236. GetDItem(GetSelection,I_B1Text, &DType, &DItem, &tempRect);
  237. SetIText(DItem, MInfo.Button1);
  238. GetDItem(GetSelection,I_B2Text, &DType, &DItem, &tempRect);
  239. SetIText(DItem, MInfo.Button2);
  240. GetDItem(GetSelection,I_B3Text, &DType, &DItem, &tempRect);
  241. SetIText(DItem, MInfo.Button3);
  242. GetDItem(GetSelection,I_CQText, &DType, &DItem, &tempRect);
  243. SetIText(DItem, MInfo.CharEquiv);
  244.  
  245. ShowWindow(GetSelection);
  246. SelectWindow(GetSelection);
  247. SetPort(GetSelection);
  248.  
  249. ExitDialog = FALSE;
  250. FlushEvents(everyEvent, 0);
  251. do { /* Modal Dialog Loop */
  252.     ModalDialog(&MyFilter, &itemHit); 
  253.     GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);
  254.      
  255.     if ((itemHit == I_OK) || (itemHit == I_Cancel)) ExitDialog =TRUE;
  256.     
  257.     if (itemHit == 999) { /* Check for PopUp Menu */
  258.         ChangedSelection = FALSE;
  259.         
  260.         if (PtInRect(myPt,&PopUpDefaultRect)) {    /* check in PopUpDefault */        
  261.             tempMenu= GetMenu(51);
  262.             if (tempMenu != NIL) { /* Got Menu */
  263.                 InsertMenu (tempMenu,-1);
  264.                 SetRect(&tempRect,215,37,275,53);
  265.                 InvertRect(&tempRect);
  266.                 myPt.v  = 37;
  267.                 myPt.h  = 275;
  268.                 LocalToGlobal(&myPt);
  269.                 
  270.                 CheckItem(tempMenu,Popup_I_Default,TRUE);
  271.                 Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h,  Popup_I_Default);
  272.                 
  273.                 if ((Popup_I_Default != LoWord(Result)) && (LoWord(Result) > 0)) {
  274.                     CheckItem(tempMenu,Popup_I_Default,FALSE);
  275.                     ChangedSelection = TRUE;
  276.                     Popup_I_Default = LoWord(Result);
  277.                     } /* Changed Selection */
  278.                 
  279.                 DeleteMenu(51);
  280.                 InvertRect(&tempRect);
  281.                 
  282.                 if (ChangedSelection == TRUE) { /* Redraw Menu */
  283.                     SetRect(&tempRect,275,37,300,52);
  284.                     EraseRect(&tempRect);
  285.                     
  286.                     MoveTo(tempRect.left + 12,tempRect.top + 12);
  287.                     switch (Popup_I_Default) {
  288.                         case 1: 
  289.                                 DrawString("\p1");
  290.                                 break;
  291.                         case 2: 
  292.                                 DrawString("\p2");
  293.                                 break;
  294.                         case 3: 
  295.                                 DrawString("\p3");
  296.                                 break;
  297.                         default:
  298.                                 break;
  299.                         } /* of switch */
  300.                     } /* end of Redraw Menu */
  301.                 } /* end of Got Menu */
  302.             } /* end of check PopUpDefault */
  303.         
  304.         if (PtInRect(myPt,&PopUpIconRect)) { /* Check PopUpIcon */            
  305.             tempMenu= GetMenu(52);
  306.             if (tempMenu != NIL) { /* Got Menu */
  307.                 InsertMenu (tempMenu,-1);
  308.                 SetRect(&tempRect,25,197,73,213);
  309.                 InvertRect(&tempRect);
  310.                 myPt.v  = 197;
  311.                 myPt.h  = 73;
  312.                 LocalToGlobal(&myPt);
  313.                 
  314.                 CheckItem(tempMenu,Popup_I_Icons,TRUE);
  315.                 Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h,  Popup_I_Icons);
  316.                 
  317.                 if ((Popup_I_Icons != LoWord(Result)) && (LoWord(Result) > 0)) {
  318.                     CheckItem(tempMenu,Popup_I_Icons,FALSE);
  319.                     ChangedSelection = TRUE;
  320.                     Popup_I_Icons = LoWord(Result);
  321.                     } /* Changed Selection */
  322.                 
  323.                 DeleteMenu(52);
  324.                 InvertRect(&tempRect);
  325.                 
  326.                 if (ChangedSelection == TRUE) { /* Redraw Menu */
  327.                     SetRect(&tempRect,73,197,140,212);
  328.                     EraseRect(&tempRect);
  329.                     
  330.                     MoveTo(tempRect.left + 12,tempRect.top + 12);
  331.                     switch (Popup_I_Icons) {
  332.                         case 1: 
  333.                                 DrawString("\pNone");
  334.                                 break;
  335.                         case 2: 
  336.                                 DrawString("\pStop");
  337.                                 break;
  338.                         case 3: 
  339.                                 DrawString("\pNote");
  340.                                 break;
  341.                         case 4: 
  342.                                 DrawString("\pCaution");
  343.                                 break;
  344.                         default:
  345.                                 break;
  346.                         }
  347.                     } /* end of Redraw Menu */
  348.                 } /* end of Got Menu */
  349.             } /* end of Check PopUpIcon */
  350.         
  351.         if (PtInRect(myPt,&PopUpButtonsRect)) { /* Check PopUpButtons */
  352.             tempMenu= GetMenu(53);
  353.             if (tempMenu != NIL) { /* Got Menu */
  354.                 InsertMenu (tempMenu,-1);
  355.                 SetRect(&tempRect,80,37,143,53);
  356.                 InvertRect(&tempRect);
  357.                 myPt.v  = 37;
  358.                 myPt.h  = 143;
  359.                 LocalToGlobal(&myPt);
  360.                 
  361.                 CheckItem(tempMenu,Popup_I_Buttons,TRUE);
  362.                 Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h,  Popup_I_Buttons);
  363.                 
  364.                 if ((Popup_I_Buttons != LoWord(Result)) && (LoWord(Result) > 0)) {
  365.                     CheckItem(tempMenu,Popup_I_Buttons,FALSE);
  366.                     ChangedSelection = TRUE;
  367.                     Popup_I_Buttons = LoWord(Result);
  368.                     } /* Changed Selection */
  369.                 
  370.                 DeleteMenu(53);
  371.                 InvertRect(&tempRect);
  372.                 
  373.                 if (ChangedSelection == TRUE) { /* Redraw Menu */
  374.                     SetRect(&tempRect,143,37,168,52);
  375.                     EraseRect(&tempRect);
  376.                     
  377.                     MoveTo(tempRect.left + 12,tempRect.top + 12);
  378.                     switch (Popup_I_Buttons) {
  379.                         case 1: 
  380.                                 DrawString("\p0");
  381.                                 break;
  382.                         case 2: 
  383.                                 DrawString("\p1");
  384.                                 break;
  385.                         case 3: 
  386.                                 DrawString("\p2");
  387.                                 break;
  388.                         case 4: 
  389.                                 DrawString("\p3");
  390.                                 break;
  391.                         default:
  392.                                 break;
  393.                         }
  394.                     } /* end of RedrawMenu */
  395.                 } /* end of Got Menu */
  396.             } /* end of Check PopUpButtons */
  397.         
  398.         if (PtInRect(myPt,&PopUpCenterRect)) { /* Check PopUpCenter */
  399.             tempMenu= GetMenu(54);
  400.             if (tempMenu != NIL) { /* Got Menu */
  401.                 InsertMenu (tempMenu,-1);
  402.                 SetRect(&tempRect,25,162,90,178);
  403.                 InvertRect(&tempRect);
  404.                 myPt.v  = 162;
  405.                 myPt.h  = 90;
  406.                 LocalToGlobal(&myPt);
  407.                 
  408.                 CheckItem(tempMenu,Popup_I_Position,TRUE);
  409.                 Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h,  Popup_I_Position);
  410.                 
  411.                 if ((Popup_I_Position != LoWord(Result)) && (LoWord(Result) > 0)) {
  412.                     CheckItem(tempMenu,Popup_I_Position,FALSE);
  413.                     ChangedSelection = TRUE;
  414.                     Popup_I_Position = LoWord(Result);
  415.                     } /* Changed Selection */
  416.                 
  417.                 DeleteMenu(54);
  418.                 InvertRect(&tempRect);
  419.                 
  420.                 if (ChangedSelection == TRUE) { /* Redraw Menu */
  421.                     SetRect(&tempRect,90,162,167,177);
  422.                     EraseRect(&tempRect);
  423.                     
  424.                     MoveTo(tempRect.left + 12,tempRect.top + 12);
  425.                     switch (Popup_I_Position) {
  426.                         case 1: 
  427.                                 DrawString("\pCentered");
  428.                                 break;
  429.                         case 2: 
  430.                                 DrawString("\pTop Third");
  431.                                 break;
  432.                         default:
  433.                                 break;
  434.                         }
  435.                     } /* end of Redraw Menu */
  436.                 } /* end of Got Menu */
  437.             } /* end of Check PopUpPosition */
  438.          } /* of PopUp Flag */
  439. } while (ExitDialog == FALSE);
  440.  
  441. if (itemHit == I_OK ) { /* OK to get results */
  442.     /* Get results after dialog */
  443.     GetDItem(GetSelection,I_B1Text, &DType, &DItem, &tempRect);
  444.     GetIText(DItem, &(MInfo.Button1));
  445.  
  446.     GetDItem(GetSelection,I_B2Text, &DType, &DItem, &tempRect);
  447.     GetIText(DItem, &(MInfo.Button2));
  448.  
  449.     GetDItem(GetSelection,I_B3Text, &DType, &DItem, &tempRect);
  450.     GetIText(DItem, &(MInfo.Button3));
  451.  
  452.     GetDItem(GetSelection,I_CQText, &DType, &DItem, &tempRect);
  453.     GetIText(DItem, &(MInfo.CharEquiv));
  454.     MInfo.defaultItem = Popup_I_Default;
  455.     MInfo.Buttons = Popup_I_Buttons - 1;
  456.     MInfo.dIcon = Popup_I_Icons - 2;
  457.     MInfo.dPlace = Popup_I_Position + 1;
  458.     }    
  459.  
  460. DisposDialog(GetSelection); 
  461. } /* end of D_Preferences() */
  462.  
  463.  
  464.